<template>
   
    <router-link to="/user"  >
    <van-cell title="我的收货地址" icon="arrow-left" />    
    </router-link>


    <van-address-list
  
  v-model="chosenAddressId"
  :list="list"
  :disabled-list="disabledList"
  disabled-text="以上地址在配送范围"
  default-tag-text="默认"
  @add="onAdd"
  @edit="onEdit"
/>

    <!-- <van-image
    round
    width="100"
    height="100"
    fit="cover"
    class="adr"
    src="https://tse3-mm.cn.bing.net/th/id/OIP-C.fPgDEEU91HIUzgI3YP0R5wAAAA?w=149&h=178&c=7&r=0&o=5&dpr=1.9&pid=1.7"
  />
  <br><br>
          <h2>亲,您还没有收货地址~</h2> -->
          
          <van-button type="primary" class="choo"  round>选择地址</van-button>
        <van-button class="newadd" to="/newadd" round>新增地址</van-button>
        
  
  
  
    </template>
    <script setup>
import axios from '../utils/axios.js'
import { onMounted, computed, reactive, ref } from 'vue'


onMounted(() => {
  axios.get('/inquire_address').then((res) => {
    console.log(res.data);
    list.value = res.data
    list.value= list.value.map((item)=>{
      item.tel = item.phone 
      item.address = item.address_book+item.detail
      item.name =item.consignee + ((item.sex === '男') ? '先生' : '女士')
      return item
    })
   
   console.log(list);
  })
})

const show = ref(false);
    const showPopup = () => {
      show.value = true;
    };
const chosenAddressId = ref('1');
    const list =ref([
      {
        id: '1',
        name: '张三',
        tel: '13000000000',
        address: '河北省三河市燕城监狱205号',
        isDefault: true,
      },
      {
        id: '2',
        name: '李四',
        tel: '1310000000',
        address: '浙江省杭州市拱墅区莫干山路 50 号',
      },
    ]
)

    const onAdd = () => showToast('新增地址');
    const onEdit = (item, index) =>{
      console.log(item);
      axios.post('/update_address',item).then((res) => {
        
  })
    };
    
 

  </script>
  <style>
  
  .ab{
    position: relative;
      background-color:#F5F5F5;
     
      height:667px;
      margin-left: -10px;
    }
  
    
    .van-cell__title {
        font-size: 17px;
       
       
    }
    .van-cell{
      height: 50px;
    }
    .van-address-list__add {
    height:0;
    width:0;
    border: none;
    opacity: 0;
  }
  .van-field__error-message{
    margin-top: -25px;
  }
  
  
 

    .choo{
      position: absolute;
      margin-left: 200px;
      width:175px;
      margin-top: -50px;
      text-align: center;
      font-size: 16px;
     
    }
    .newadd{
      position: absolute;
      margin-left: 0px;
      width:175px;
      margin-top: -50px;
      color:black;
      font-size: 16px;
    }

    
  </style>